package com.wd.live.view.Activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import com.wd.live.R
import com.wd.live.base.BaseActivity
import com.wd.live.databinding.ActivityMainBinding
import com.wd.live.viewmodel.MainViewModel
import com.wd.myhome.view.fragment.HomeFragment
import com.wd.mylive.view.fragment.LiveFragment
import com.wd.mymine.view.fragment.MineFragment
import com.wd.myplacard.view.fragment.PlacardFragment
import com.wd.mysquare.view.fragment.SquareFragment
import org.greenrobot.eventbus.util.ErrorDialogManager.SupportManagerFragment

class MainActivity : BaseActivity<MainViewModel,ActivityMainBinding>(R.layout.activity_main){
    val img1= listOf<Int>(R.mipmap.guang1,R.mipmap.fu1,R.mipmap.kai,R.mipmap.huo1,R.mipmap.wo1)
    val img2= listOf<Int>(R.mipmap.guang2,R.mipmap.fu2,R.mipmap.kai,R.mipmap.huo2,R.mipmap.wo2)

    override fun dataObserver() {
    }
    override fun initViews() {

        val  list= listOf<Fragment>(
            HomeFragment(),
            SquareFragment(),
            LiveFragment(),
            PlacardFragment(),
            MineFragment(),
        )
        val  titles= arrayOf("广场","附近","","榜单","我的")
        for (s in titles)binding.tab1.addTab(binding.tab1.newTab().setText(s))
        binding.vp.adapter=object : FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {
               return  list.size
            }

            override fun getItem(position: Int): Fragment {
              return list.get(position)
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return titles[position]
            }

        }
        binding.vp.offscreenPageLimit=5
        binding.tab1.setupWithViewPager(binding.vp)
        binding.tab1.getTabAt(0)?.setIcon(R.mipmap.guang1)
        binding.tab1.getTabAt(1)?.setIcon(R.mipmap.fu2)
        binding.tab1.getTabAt(2)?.setIcon(R.mipmap.kai)
        binding.tab1.getTabAt(3)?.setIcon(R.mipmap.huo2)
        binding.tab1.getTabAt(4)?.setIcon(R.mipmap.wo2)
        binding.tab1.addOnTabSelectedListener(object :OnTabSelectedListener{
            override fun onTabSelected(tab: TabLayout.Tab) {
              tab.setIcon(img1[tab.position])
            }
            override fun onTabUnselected(tab: TabLayout.Tab) {

              tab.setIcon(img2[tab.position])
            }

            override fun onTabReselected(tab: TabLayout.Tab?) {


            }

        })





    }
}